package ru.ifmo.ctddev.krotkov.helloudp;

import java.io.IOException;
import java.net.*;
import java.util.concurrent.*;

public class HelloUDPServer {

	void run(int port) {
		DatagramSocket socket = null;
		try {
			socket = new DatagramSocket(port);

		} catch (SocketException e) {
			e.printStackTrace();
		}
		Executor pool = Executors.newFixedThreadPool(5);
		while (true) {
			byte[] buf = new byte[100];
			DatagramPacket q = new DatagramPacket(buf, 100);
			try {
				socket.receive(q);
			} catch (IOException e) {
				e.printStackTrace();
			}
			Task t = new Task(socket, q);
			pool.execute(t);

		}
	}

	public static void main(String[] args) {
		new HelloUDPServer().run(Integer.valueOf(args[0]));
	}
}
